import 'package:flutter/material.dart';
import 'ui/button.dart';
import 'ui/card.dart';
import 'ui/list.dart';
import 'ui/switch.dart';
import 'ui/text.dart';

final routes = {
  'ButtonPage': (context) => const ButtonPage(),
  'CardPage': (context) => const CardPage(),
  'ListPage': (context) => const ListPage(),
  'SwitchPage': (context) => const SwitchPage(),
  'TextPage': (context) => const TextPage(),
};

// 路由跳转
var onGenerateRoute = (RouteSettings settings) {
  final String? name = settings.name;
  final Function pageContentBuilder = routes[name] as Function;
  if (pageContentBuilder != null) {
    // 路由传参
    if (settings.arguments != null) {
      final Route route = MaterialPageRoute(
          builder: (context) =>
              pageContentBuilder(context, arguments: settings.arguments));
      return route;
    } else {
      // 路由无参
      final Route route =
          MaterialPageRoute(builder: (context) => pageContentBuilder(context));
      return route;
    }
  }
};
